package com.qnw.CardGroupManagement;
import android.app.*;
import android.content.*;
import android.graphics.*;
import android.os.*;
import android.support.v7.app.*;
import android.support.v7.widget.*;
import android.text.*;
import android.util.*;
import android.view.*;
import android.view.View.*;
import android.view.ViewGroup.*;
import android.widget.*;
import com.ygo.feihua.*;
import java.io.*;
import java.util.*;

import android.support.v7.widget.Toolbar;
import android.view.View.OnClickListener;
import android.widget.RadioGroup.*;
import com.ygo.feihua.util.*;
import com.xiaomi.mistatistic.sdk.*;
import com.ygo.feihua.Management.*;

public class H5 extends AppCompatActivity implements OnClickListener
{
	private Dialog builder;
	private String sjk_path;
	private EditText ed_cjm;
	private ImageButton ib_g0;
	private ImageButton ib_g1;
	private ImageButton ib_g2;
	private ImageButton ib_g3;
	private ImageButton ib_g4;
	private ImageButton ib_g5;
	private ImageButton ib_g6;
	private ImageButton ib_g7;
	private ImageButton ib_g8;
	private ImageButton ib_g9;
	private ImageButton ib_m0;
	private ImageButton ib_m1;
	private ImageButton ib_m2;
	
	private ImageButton ib_m7;
	private ImageButton ib_m8;
	private ImageButton ib_m9;
	private ImageButton ib_m10;
	private ImageButton ib_m11;
	private ImageButton ib_m12;
	private ImageButton ib_m13;
	private ImageButton ib_m14;
	private ImageButton ib_m15;
	private ImageButton ib_d0;
	private ImageButton ib_d1;
	private ImageButton ib_d2;
	private ImageButton ib_d3;
	private ImageButton ib_d4;
	private ImageButton ib_d5;
	private ImageButton ib_d6;
	private ImageButton ib_d7;
	
	private ImageButton ib_link1,ib_link2;
	
	private Gongju gj;
	private DialogUtils du;
	Handler han=new Handler(){

		@Override
		public void handleMessage(Message msg)
		{
			// TODO: Implement this method
			super.handleMessage(msg);
			switch(msg.what){	
				case 0:
					Object[] oo= (Object[]) msg.obj;
					((ImageView)oo[0]).setImageBitmap((Bitmap)oo[1]);
					break;		
			}				
		}	
	};
	String card_km;

	private String CJ_VERSION="1";
	
	//设置主怪兽区域卡片
	public void szgs(String title,final ArrayList al,final ImageButton im,int bs,final int ii){
		
		builder = new Dialog(this,R.style.dialog);
		//去除原dialog标题
		builder.requestWindowFeature(Window.FEATURE_NO_TITLE);
		builder.show();

		LayoutInflater inflater = LayoutInflater.from(this);
		View viewDialog = inflater.inflate(R.layout.h5_dialog_4, null);
		Display display = this.getWindowManager().getDefaultDisplay();
		int width = display.getWidth();
		//int hight=display.getHeight();
		//设置对话框的宽高
		LayoutParams layoutParams = new LayoutParams(width * 80 / 100, LayoutParams.WRAP_CONTENT);
		builder.setContentView(viewDialog, layoutParams);
		final EditText ed_sc=(EditText)viewDialog.findViewById(R.id.h5d_4_sc);
		final RadioGroup rg_dx=(RadioGroup)viewDialog.findViewById(R.id.h5d_4_dx);
		TextView tv_title=(TextView) viewDialog.findViewById(R.id.h5d_4_title);
		Button bu_qd=(Button)viewDialog.findViewById(R.id.h5d_4_qd);
		LinearLayout lin=(LinearLayout) viewDialog.findViewById(R.id.h5d_4_lin);
		final ImageView iv_kt=(ImageView) viewDialog.findViewById(R.id.h5d_4_kt);
		Button bu_del=(Button) viewDialog.findViewById(R.id.h5d_4_del);
		final RadioGroup rg_control=(RadioGroup)viewDialog.findViewById(R.id.h5d_4_control);
		LinearLayout lin1=(LinearLayout) viewDialog.findViewById(R.id.h5d_4_lin1);

		 switch(ii){
			 case 10:
				 if(islink1){
				 rg_control.check(R.id.h5d_4_rb0);
				 }else{
				rg_control.check(R.id.h5d_4_rb1);
				 }
				 break;
			case 11:
				 if(islink2){
					 rg_control.check(R.id.h5d_4_rb0);
				 }else{
					 rg_control.check(R.id.h5d_4_rb1);
				 }
				break;
			default:
			lin1.setVisibility(View.GONE);
			break;
		 }
		 
		
		
		viewDialog.measure(0,0);
		LayoutParams lp=iv_kt.getLayoutParams();
		int height1=lin.getMeasuredHeight()*8/10;//.getHeight()*8/10;
		int width1=height1*177/254;
		lp.height=height1;
		lp.width=width1;
		iv_kt.setLayoutParams(lp);
		
		tv_title.setText(title);
	
		iv_kt.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					DialogUtils.CardList cl= du.dialogCxCards();
					cl.setOnCardItemClickListener(new DialogUtils.OnCardItemClickListener(){

							@Override
							public void onClick(final Card card)
							{
								card_km=card.getId();
								du.dis();
								Gongju.setKt(H5.this,iv_kt,card_km);
								// TODO: Implement this method
							}
						});
					// TODO: Implement this method
				}
			});
		
		RadioButton r = (RadioButton)rg_dx.getChildAt(bs);
		//设置表示形式
		r.setChecked(true);
		//设置卡密
		switch(ii){
			case 0:
				card_km=g0_0_km;
				//ed_km.setText(g0_0_km);
				break;
			case 1:
				card_km=g0_1_km;
				//ed_km.setText(g0_1_km);
				break;
			case 2:
				card_km=g0_2_km;
				//ed_km.setText(g0_2_km);
				break;
			case 3:
				card_km=g0_3_km;
				//ed_km.setText(g0_3_km);
				break;
			case 4:
				card_km=g0_4_km;
				//ed_km.setText(g0_4_km);
				break;
			case 5:
				card_km=g1_4_km;
				//ed_km.setText(g1_4_km);
				break;
			case 6:
				card_km=g1_3_km;
				//ed_km.setText(g1_3_km);
				break;
			case 7:
				card_km=g1_2_km;
				//ed_km.setText(g1_2_km);
				break;
			case 8:
				card_km=g1_1_km;
			//	ed_km.setText(g1_1_km);
				break;
			case 9:
				card_km=g1_0_km;
				//ed_km.setText(g1_0_km);
				break;
			case 10:
				if(islink1){
					card_km=g0_5_km;
				}else{
					card_km=g1_6_km;
				}
				break;
			case 11:
				if(islink2){
					card_km=g0_6_km;
				}else{
					card_km=g1_5_km;
				}
				break;
				
			default:
				card_km="";
				break;
		}

			Gongju.setKt(this,iv_kt,card_km);
		
		
		//设置超量素材
		String sss="";
		for (int i=0;i < al.size();i++)
		{
			sss = sss + al.get(i) + "\n";
		}
		ed_sc.setText(sss);
		
		bu_del.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					//如果卡密为空恢复默认
					im.setImageBitmap(null);//.setImageBitmap(null);
					al.clear();
					switch(ii){
						case 0:
							g0_0_km="";
							break;
						case 1:
							g0_1_km = "";
							break;
						case 2:
							g0_2_km = "";
							break;
						case 3:
							g0_3_km = "";
							break;

						case 4:
							g0_4_km = "";
							break;
						case 5:
							g1_4_km = "";
							break;
						case 6:
							g1_3_km = "";
							break;
						case 7:
							g1_2_km = "";
							break;
						case 8:
							g1_1_km = "";
							break;
						case 9:
							g1_0_km = "";
							break;
						case 10:
							if(islink1){
								g0_5_km="";
							}else{
								g1_6_km="";
							}
							break;
						case 11:
							if(islink2){
								g0_6_km="";
							}else{
								g1_5_km="";
							}
							break;
							}
							
							
					builder.dismiss();
							
					// TODO: Implement this method
				}
			});
		
		bu_qd.setOnClickListener(new OnClickListener(){
				public void onClick(View p1)
				{
					switch(rg_control.getCheckedRadioButtonId()){
						case R.id.h5d_4_rb0:
							switch(ii){
								case 10:
									islink1=true;
									break;
								case 11:
									islink2=true;
									break;
							}
							break;
						case R.id.h5d_4_rb1:
							switch(ii){
								case 10:
									islink1=false;
									break;
								case 11:
									islink2=false;
									break;
							}
							break;
					}
					//获取表示形式
					String s=card_km;
						//设置卡密
						switch(ii){
							case 0:
								g0_0_km=s;
								break;
							case 1:
								g0_1_km=s;
								break;
							case 2:
								g0_2_km=s;
								break;
							case 3:
								g0_3_km=s;
								break;
							case 4:
								g0_4_km=s;
								break;
							case 5:
								g1_4_km=s;
								break;
							case 6:
								g1_3_km=s;
								break;
							case 7:
								g1_2_km=s;
								break;
							case 8:
								g1_1_km=s;
								break;
							case 9:
								g1_0_km=s;
								break;
							case 10:
								if(islink1){
									g0_5_km=s;
									g1_6_km="";
								}else{
									g1_6_km=s;
									g0_5_km="";
								}
								break;
							case 11:
								if(islink2){
									g0_6_km=s;
									g1_5_km="";
								}else{
									g1_5_km=s;
									g0_6_km="";
								}
						}
					
						
					for (int i=0; i < rg_dx.getChildCount(); i++)
					{  
						RadioButton r = (RadioButton)rg_dx.getChildAt(i);  
						if (r.isChecked())
						{  
							s = r.getText().toString();  
							if (s.equals("表侧攻击表示"))
							{
								gs_bss=0;
								switch(ii){
									case 0:
										g0_0_bs = "POS_FACEUP_ATTACK";
										g0_0_bss = 0;
										break;
									case 1:
										g0_1_bs = "POS_FACEUP_ATTACK";
										g0_1_bss = 0;
										break;
									case 2:
										g0_2_bs = "POS_FACEUP_ATTACK";
										g0_2_bss = 0;
										break;
									case 3:
										g0_3_bs = "POS_FACEUP_ATTACK";
										g0_3_bss = 0;
										break;
									case 4:
										g0_4_bs = "POS_FACEUP_ATTACK";
										g0_4_bss = 0;
										break;
									case 5:
										g1_4_bs = "POS_FACEUP_ATTACK";
										g1_4_bss = 0;
										break;
									case 6:
										g1_3_bs = "POS_FACEUP_ATTACK";
										g1_3_bss = 0;
										break;
									case 7:
										g1_2_bs = "POS_FACEUP_ATTACK";
										g1_2_bss = 0;
										break;
									case 8:
										g1_1_bs = "POS_FACEUP_ATTACK";
										g1_1_bss = 0;
										break;
									case 9:
										g1_0_bs = "POS_FACEUP_ATTACK";
										g1_0_bss = 0;
										break;
										
									case 10:
										if(islink1){
											g0_5_bs = "POS_FACEUP_ATTACK";
											g0_5_bss = 0;
										}else{
											g1_6_bs = "POS_FACEUP_ATTACK";
											g1_6_bss = 0;
										}
										break;
									case 11:
										if(islink2){
											g0_6_bs = "POS_FACEUP_ATTACK";
											g0_6_bss = 0;
										}else{
											g1_5_bs = "POS_FACEUP_ATTACK";
											g1_5_bss = 0;
										}
										
								}		
							}else if (s.equals("表侧守备表示")){
								gs_bss=1;
								switch(ii){
									case 0:
										g0_0_bs = "POS_FACEUP_DEFENCE";
										g0_0_bss = 1;
										break;
									case 1:
										g0_1_bs = "POS_FACEUP_DEFENCE";
										g0_1_bss = 1;
										break;
									case 2:
										g0_2_bs = "POS_FACEUP_DEFENCE";
										g0_2_bss = 1;
										break;
									case 3:
										g0_3_bs = "POS_FACEUP_DEFENCE";
										g0_3_bss = 1;
										break;
									case 4:
										g0_4_bs = "POS_FACEUP_DEFENCE";
										g0_4_bss = 1;
										break;
									case 5:
										g1_4_bs = "POS_FACEUP_DEFENCE";
										g1_4_bss = 1;
										break;
									case 6:
										g1_3_bs = "POS_FACEUP_DEFENCE";
										g1_3_bss = 1;
										break;
									case 7:
										g1_2_bs = "POS_FACEUP_DEFENCE";
										g1_2_bss = 1;
										break;
									case 8:
										g1_1_bs = "POS_FACEUP_DEFENCE";
										g1_1_bss = 1;
										break;
										
									case 9:
										g1_0_bs = "POS_FACEUP_DEFENCE";
										g1_0_bss = 1;
										break;
										
									case 10:
										if(islink1){
											g0_5_bs = "POS_FACEUP_DEFENCE";
											g0_5_bss = 1;
										}else{
											g1_6_bs = "POS_FACEUP_DEFENCE";
											g1_6_bss = 1;
										}
										break;
									case 11:
										if(islink2){
											g0_6_bs = "POS_FACEUP_DEFENCE";
											g0_6_bss = 1;
										}else{
											g1_5_bs = "POS_FACEUP_DEFENCE";
											g1_5_bss = 1;
										}
								}		
							}else if (s.equals("里侧攻击表示")){
								gs_bss=2;
								
								switch(ii){
									case 0:
										g0_0_bs = "POS_FACEDOWN_ATTACK";
										g0_0_bss = 2;
										break;
									case 1:
										g0_1_bs = "POS_FACEDOWN_ATTACK";
										g0_1_bss = 2;
										break;
									case 2:
										g0_2_bs = "POS_FACEDOWN_ATTACK";
										g0_2_bss = 2;
										break;
									case 3:
										g0_3_bs = "POS_FACEDOWN_ATTACK";
										g0_3_bss = 2;
										break;
									case 4:
										g0_4_bs = "POS_FACEDOWN_ATTACK";
										g0_4_bss = 2;
										break;
									case 5:
										g1_4_bs = "POS_FACEDOWN_ATTACK";
										g1_4_bss = 2;
										break;
									case 6:
										g1_3_bs = "POS_FACEDOWN_ATTACK";
										g1_3_bss = 2;
										break;
									case 7:
										g1_2_bs = "POS_FACEDOWN_ATTACK";
										g1_2_bss = 2;
										break;
									case 8:
										g1_1_bs = "POS_FACEDOWN_ATTACK";
										g1_1_bss = 2;
										break;
									case 9:
										g1_0_bs = "POS_FACEDOWN_ATTACK";
										g1_0_bss = 2;
										break;
										
									case 10:
										if(islink1){
											g0_5_bs = "POS_FACEDOWN_ATTACK";
											g0_5_bss = 2;
										}else{
											g1_6_bs = "POS_FACEDOWN_ATTACK";
											g1_6_bss = 2;
										}
										break;
									case 11:
										if(islink2){
											g0_6_bs = "POS_FACEDOWN_ATTACK";
											g0_6_bss = 2;
										}else{
											g1_5_bs = "POS_FACEDOWN_ATTACK";
											g1_5_bss = 2;
										}
								}
							}else{
								gs_bss=3;
								switch(ii){
									case 0:
										g0_0_bs = "POS_FACEDOWN_DEFENCE";
										g0_0_bss = 3;
										break;
									case 1:
										g0_1_bs = "POS_FACEDOWN_DEFENCE";
										g0_1_bss = 3;
										break;
									case 2:
										g0_2_bs = "POS_FACEDOWN_DEFENCE";
										g0_2_bss = 3;
										break;
									case 3:
										g0_3_bs = "POS_FACEDOWN_DEFENCE";
										g0_3_bss = 3;
										break;
									case 4:
										g0_4_bs = "POS_FACEDOWN_DEFENCE";
										g0_4_bss = 3;
										break;
									case 5:
										g1_4_bs = "POS_FACEDOWN_DEFENCE";
										g1_4_bss = 3;
										break;
									case 6:
										g1_3_bs = "POS_FACEDOWN_DEFENCE";
										g1_3_bss = 3;
										break;
									case 7:
										g1_2_bs = "POS_FACEDOWN_DEFENCE";
										g1_2_bss = 3;
										break;
									case 8:
										g1_1_bs = "POS_FACEDOWN_DEFENCE";
										g1_1_bss = 3;
										break;
									case 9:
										g1_0_bs = "POS_FACEDOWN_DEFENCE";
										g1_0_bss = 3;
										break;
									case 10:
										if(islink1){
											g0_5_bs = "POS_FACEDOWN_DEFENCE";
											g0_5_bss = 3;
										}else{
											g1_6_bs = "POS_FACEDOWN_DEFENCE";
											g1_6_bss = 3;
										}
										break;
									case 11:
										if(islink2){
											g0_6_bs = "POS_FACEDOWN_DEFENCE";
											g0_6_bss = 3;
										}else{
											g1_5_bs = "POS_FACEDOWN_DEFENCE";
											g1_5_bss = 3;
										}
								}	
							}
							break;
						}  
					}
					
					if(!card_km.equals("")){
						new Thread(new Runnable(){

							
								@Override
								public void run()
								{
									Bitmap bt = null;
									switch(gs_bss){
										case 0:
											bt=gj.getkt1(card_km);
											break;
										case 1:
											bt=BitmapUtil.rotatingBitmap( gj.getkt1(card_km),90);
											break;
										case 2:
											bt=BitmapFactory.decodeResource(getResources(), R.drawable.cover);		
											break;
										case 3:
											bt=BitmapUtil.rotatingBitmap( BitmapFactory.decodeResource(getResources(), R.drawable.cover),90);			
											break;	
										default:
											bt=BitmapFactory.decodeResource(getResources(), R.drawable.unknown);
										break;
									}
									Object[] oo={im,bt};
									Message me=new Message();
									me.what=0;
									me.obj=oo;
									han.sendMessage(me);
									// TODO: Implement this method
								}
							}).start();

					}
					
					
					//清空超量素材列表
					al.clear();
					//获取超量素材
					String[] ss=ed_sc.getText().toString().trim().split("\n");
					for (int i=0;i < ss.length;i++)
					{
						if (!ss[i].equals(""))
						{
							al.add(ss[i]);
						}
					}					
					//关闭对话框
					builder.dismiss();
				}		
			});
	}
	
	private void setList(String title,final ImageButton ib,final ArrayList al){
		
		View[] v=du.dialoge(true,title,"每行一个卡密");
		
		final EditText ed_kms=(EditText) v[0];//(EditText)viewDialog.findViewById(R.id.h5d_7_kms);
		Button bu_qd=(Button)v[1];//viewDialog.findViewById(R.id.h5d_7_qd);
		String sss="";
		for (int i=0;i < al.size();i++)
		{
			sss = sss + al.get(i) + "\n";
		}
		ed_kms.setText(sss);
		bu_qd.setOnClickListener(new OnClickListener(){
				public void onClick(View p1)
				{
					String s=ed_kms.getText().toString().trim();
					if (TextUtils.isEmpty(s))
					{
						ib.setImageBitmap(null);
						
					}else{
						ib.setImageResource(R.drawable.image_16);
					}
					al.clear();
					String[] ss=ed_kms.getText().toString().trim().split("\n");
					for (int i=0;i < ss.length;i++)
					{
						if (!ss[i].equals(""))
						{
							al.add(ss[i]);
						}
					}			
					du.dis();
				}		
			});
	}
	

	@Override
	protected void onResume(){
		// TODO: Implement this method
		super.onResume();
		SdkInitManagement.getDx().initMiStats();
		MiStatInterface.recordPageStart(this, "残局编辑");
	}

	@Override
	protected void onPause(){
		// TODO: Implement this method
		super.onPause();
		MiStatInterface.recordPageEnd();
	}
	
	
	
	
	private void setMx(String title,final ImageButton im,final int ii,int bs,final ArrayList azb,final ArrayList wzb){
		builder = new Dialog(this,R.style.dialog);
		//去除原dialog标题
		builder.requestWindowFeature(Window.FEATURE_NO_TITLE);
		
		builder.show();

		LayoutInflater inflater = LayoutInflater.from(this);
		View viewDialog = inflater.inflate(R.layout.h5_dialog_5, null);
		Display display = this.getWindowManager().getDefaultDisplay();
		int width = display.getWidth();
		//int hight=display.getHeight();
		//设置对话框的宽高
		LayoutParams layoutParams = new LayoutParams(width * 80 / 100, LayoutParams.WRAP_CONTENT);
		builder.setContentView(viewDialog, layoutParams);
		final EditText ed_azb=(EditText)viewDialog.findViewById(R.id.h5d_5_azb);
		final EditText ed_wzb=(EditText)viewDialog.findViewById(R.id.h5d_5_wzb);
		final RadioGroup rg_dx=(RadioGroup)viewDialog.findViewById(R.id.h5d_5_dx);
		Button bu_qd=(Button)viewDialog.findViewById(R.id.h5d_5_qd);
		Button bu_del=(Button) viewDialog.findViewById(R.id.h5d_5_del);
		final ImageView iv_kt=(ImageView) viewDialog.findViewById(R.id.h5d_5_kt);
		TextView tv_title=(TextView) viewDialog.findViewById(R.id.h5d_5_title);
		tv_title.setText(title);
		viewDialog.measure(0,0);
		LayoutParams lp=iv_kt.getLayoutParams();
		int height1=rg_dx.getMeasuredHeight()*2*8/10;//.getHeight()*8/10;
		int width1=height1*177/254;
		lp.height=height1;
		lp.width=width1;
		iv_kt.setLayoutParams(lp);
		switch(ii){
			case 0:
				card_km=m1_0_km;
				break;
			case 1:
				card_km=m1_1_km;
				break;
			case 2:
				card_km=m1_2_km;
				break;
			case 3:
				card_km=m1_7_km;
				break;
			case 4:
				card_km=m1_8_km;
				break;
			case 5:
				card_km=m1_9_km;
				break;
			case 6:
				//玩家左刻度
				card_km=m1_10_km;
				break;
			case 7:
				//玩家右刻度
				card_km=m1_11_km;
				break;
			case 8:
				//ai右刻度
				card_km=m1_12_km;
				break;
			case 9:
				//ai左刻度
				card_km=m1_13_km;
				break;
			case 10:
				card_km=m1_14_km;
				break;
			case 11:
				card_km=m1_15_km;
				break;
			default:
			card_km="";
			break;

		}
			Gongju.setKt(this,iv_kt,card_km);
		
		iv_kt.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					DialogUtils.CardList cl= du.dialogCxCards();
					cl.setOnCardItemClickListener(new DialogUtils.OnCardItemClickListener(){

							@Override
							public void onClick(final Card card)
							{
								card_km=card.getId();
								du.dis();					
								Gongju.setKt(H5.this,iv_kt,card_km);
								// TODO: Implement this method
							}
						});
					// TODO: Implement this method
				}
			});
		
		
		RadioButton r = (RadioButton)rg_dx.getChildAt(bs);  
		r.setChecked(true);
		
		String sss="";
		for (int i=0;i < azb.size();i++)
		{
			sss = sss + azb.get(i) + ",";
		}
		ed_azb.setText(sss);
		sss="";
		for (int i=0;i < wzb.size();i++)
		{
			sss = sss + wzb.get(i) + ",";
		}
		ed_wzb.setText(sss);
		bu_del.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					im.setImageBitmap(null);
					switch(ii){
						case 0:
							m1_0_km ="";
							break;
						case 1:
							m1_1_km ="";
							break;
						case 2:
							m1_2_km ="";
							break;
						case 3:
							m1_7_km ="";
							break;
						case 4:
							m1_8_km ="";
							break;
						case 5:
							m1_9_km ="";
							break;
						case 6:
							//玩家左刻度
							m1_10_km ="";
							break;
						case 7:
							//玩家右刻度
							m1_11_km ="";
							break;
						case 8:
							//ai右刻度
							m1_12_km ="";
							break;
						case 9:
							//ai左刻度
							m1_13_km ="";
							break;
						case 10:
							m1_14_km="";
							break;
						case 11:
							m1_15_km="";
							break;
							
						
					}
					builder.dismiss();
					// TODO: Implement this method
				}
			});
		
		bu_qd.setOnClickListener(new OnClickListener(){
				public void onClick(View p1)
				{
			
					
					switch(ii){
						case 0:
							m1_0_km =card_km;
							break;
						case 1:
							m1_1_km =card_km;
							break;
						case 2:
							m1_2_km =card_km;
							break;
						case 3:
							m1_7_km =card_km;
							break;
						case 4:
							m1_8_km =card_km;
							break;
						case 5:
							m1_9_km =card_km;
							break;
						case 6:
							//玩家左刻度
							m1_10_km =card_km;
							break;
						case 7:
							//玩家右刻度
							m1_11_km =card_km;
							break;
						case 8:
							//ai右刻度
							m1_12_km =card_km;
							break;
						case 9:
							//ai左刻度
							m1_13_km =card_km;
							break;
						case 10:
							m1_14_km=card_km;
							break;
						case 11:
							m1_15_km=card_km;
							break;
							
			

					}
			
					for (int i=0; i < rg_dx.getChildCount(); i++)
					{  
						RadioButton r = (RadioButton)rg_dx.getChildAt(i);  
						if (r.isChecked())
						{  
							String s = r.getText().toString();  
							if (s.equals("表侧表示"))
							{
								mx_bss=0;
								switch(ii){
									case 0:
										m1_0_bs = "POS_FACEUP";
										m1_0_bss = 0;
										break;
									case 1:
										m1_1_bs = "POS_FACEUP";
										m1_1_bss = 0;
										break;
									case 2:
										m1_2_bs = "POS_FACEUP";
										m1_2_bss = 0;
										break;
									case 3:
										m1_7_bs = "POS_FACEUP";
										m1_7_bss = 0;
										break;
									case 4:
										m1_8_bs = "POS_FACEUP";
										m1_8_bss = 0;
										break;
									case 5:
										m1_9_bs = "POS_FACEUP";
										m1_9_bss = 0;
										break;
									case 6:
										//玩家左刻度
										m1_10_bs = "POS_FACEUP";
										m1_10_bss = 0;
										break;
									case 7:
										//玩家右刻度
										m1_11_bs = "POS_FACEUP";
										m1_11_bss = 0;
										break;
									case 8:
										//ai右刻度
										m1_12_bs = "POS_FACEUP";
										m1_12_bss = 0;
										break;
									case 9:
										//ai左刻度
										m1_13_bs = "POS_FACEUP";
										m1_13_bss = 0;
										break;
									case 10:
										m1_14_bs = "POS_FACEUP";
										m1_14_bss = 0;
										break;
									case 11:
										m1_15_bs = "POS_FACEUP";
										m1_15_bss = 0;
										break;

								}		
							}else{
				
								mx_bss=1;
								switch(ii){
									case 0:
										m1_0_bs = "POS_FACEDOWN";
										m1_0_bss = 1;
										break;
									case 1:
										m1_1_bs = "POS_FACEDOWN";
										m1_1_bss = 1;
										break;
									case 2:
										m1_2_bs = "POS_FACEDOWN";
										m1_2_bss = 1;
										break;
									case 3:
										m1_7_bs = "POS_FACEDOWN";
										m1_7_bss = 1;
										break;
									case 4:
										m1_8_bs = "POS_FACEDOWN";
										m1_8_bss = 1;
										break;
									case 5:
										m1_9_bs = "POS_FACEDOWN";
										m1_9_bss = 1;
										break;
									case 6:
										//玩家左刻度
										m1_10_bs = "POS_FACEDOWN";
										m1_10_bss = 1;
										break;
									case 7:
										//玩家右刻度
										m1_11_bs = "POS_FACEDOWN";
										m1_11_bss = 1;
										break;
									case 8:
										//ai右刻度
										m1_12_bs = "POS_FACEDOWN";
										m1_12_bss = 1;
										break;
									case 9:
										//ai左刻度
										m1_13_bs = "POS_FACEDOWN";
										m1_13_bss = 1;
										break;
									case 10:
										m1_14_bs = "POS_FACEDOWN";
										m1_14_bss = 1;
										break;
									case 11:
										m1_15_bs = "POS_FACEDOWN";
										m1_15_bss = 1;
										break;
										
								
								}
							}
							break;
						}  
					}
					
					if(!card_km.equals("")){
						new Thread(new Runnable(){


								@Override
								public void run()
								{
									Bitmap bt = null;
									switch(mx_bss){
										case 0:
											bt=gj.getkt1(card_km);
											break;
										case 1:
											bt=BitmapFactory.decodeResource(getResources(), R.drawable.cover);
											break;
										default:
											bt=BitmapFactory.decodeResource(getResources(), R.drawable.unknown);
											break;
									}
									Object[] oo={im,bt};
									Message me=new Message();
									me.what=0;
									me.obj=oo;
									han.sendMessage(me);
									// TODO: Implement this method
								}
							}).start();

					}
					
					
					
					azb.clear();
					wzb.clear();
					String[] ss=ed_azb.getText().toString().trim().split(",");
					for (int i=0;i < ss.length;i++)
					{
						if (!ss[i].equals(""))
						{
							azb.add(ss[i]);
						}
					}		
					ss=ed_wzb.getText().toString().trim().split(",");
					for (int i=0;i < ss.length;i++)
					{
						if (!ss[i].equals(""))
						{
							wzb.add(ss[i]);
						}
					}			
					builder.dismiss();
				}		
			});
		
		
	}
	
	private int gs_bss;
	private int mx_bss;
	
	
	private OnSetKt oncard;
	public interface OnSetKt{
		void onsetkt(ImageButton im,String km,int type,int bs);	
	}



	public class SetKt{
		public void setOnSetKt(OnSetKt oncar){
			oncard=oncar;
		}
	}
	public void setkt(final SetKt st){
		new Thread(new Runnable(){

				@Override
				public void run()
				{
					st.setOnSetKt(new OnSetKt(){

							@Override
							public void onsetkt(ImageButton im, String km, int type, int bs)
							{
								
								Bitmap bt = null;
								if(!km.equals("")){
								switch(type){
									case 0:
										
										switch(bs){
											case 0:
												bt=gj.getkt1(km);
												break;
											case 1:
												bt=BitmapUtil.rotatingBitmap( gj.getkt1(km),90);
												break;
											case 2:
												bt=BitmapFactory.decodeResource(getResources(), R.drawable.cover);		
												break;
											case 3:
												bt=BitmapUtil.rotatingBitmap( BitmapFactory.decodeResource(getResources(), R.drawable.cover),90);			
												break;	
											default:
												bt=BitmapFactory.decodeResource(getResources(), R.drawable.unknown);
												break;
										}
										
										break;
									case 1:
								
										switch(bs){
											case 0:
												bt=gj.getkt1(km);
												break;
											case 1:
												bt=BitmapFactory.decodeResource(getResources(), R.drawable.cover);
												break;
											default:
												bt=BitmapFactory.decodeResource(getResources(), R.drawable.unknown);
												break;
										}
										
										break;
								}
								}
								Object[] oo={im,bt};
								Message me=new Message();
								me.what=0;
								me.obj=oo;
								han.sendMessage(me);
								
								// TODO: Implement this method
							}
						});
					
					
				}
					
			}).start();
		
	}
	
	
	public void onClick(View p1)
	{
		switch (p1.getId())
		{
			case R.id.h5_ib_g0:
				szgs("设置玩家怪兽区域0(g0)", g0_0_sc, ib_g0, g0_0_bss, 0);
				break;
			case R.id.h5_ib_g1:
				szgs("设置玩家怪兽区域1(g1)", g0_1_sc, ib_g1, g0_1_bss, 1);
				break;
			case R.id.h5_ib_g2:
				szgs("设置玩家怪兽区域2(g2)", g0_2_sc, ib_g2, g0_2_bss, 2);
				break;
			case R.id.h5_ib_g3:
				szgs("设置玩家怪兽区域3(g3)", g0_3_sc, ib_g3, g0_3_bss, 3);
				break;
			case R.id.h5_ib_g4:
				szgs("设置玩家怪兽区域4(g4)", g0_4_sc, ib_g4, g0_4_bss, 4);
				break;
			case R.id.h5_ib_g5:
				szgs("设置AI怪兽区域4(g4)", g1_4_sc, ib_g5, g1_4_bss, 5);
				break;
			case R.id.h5_ib_g6:
				szgs("设置AI怪兽区域3(g3)", g1_3_sc, ib_g6, g1_3_bss, 6);
				break;
			case R.id.h5_ib_g7:
				szgs("设置AI怪兽区域2(g2)", g1_2_sc, ib_g7, g1_2_bss, 7);
				break;
			case R.id.h5_ib_g8:
				szgs("设置AI怪兽区域1(g1)", g1_1_sc, ib_g8, g1_1_bss, 8);
				break;
			case R.id.h5_ib_g9:
				szgs("设置AI怪兽区域0(g0)", g1_0_sc, ib_g9, g1_0_bss, 9);
				break;
			case R.id.h5_ib_link1:
				if (islink1){
					szgs("设置LINK区域0", g0_5_sc, ib_link1, g0_5_bss, 10);	
				}else{
					szgs("设置LINK区域0", g1_6_sc, ib_link1, g1_6_bss, 10);
				}
				break;
			case R.id.h5_ib_link2:
				if (islink2){
					szgs("设置LINK区域1", g0_6_sc, ib_link2, g0_6_bss, 11);
				}else{
					szgs("设置LINK区域1", g1_5_sc, ib_link2, g1_5_bss, 11);
				}
				break;
			case R.id.h5_ib_m0:
				setMx("设置玩家魔法区域0(m0)", ib_m0, 0, m1_0_bss, m1_0_azb, m1_0_wzb);
				break;
			case R.id.h5_ib_m1:
				setMx("设置玩家魔法区域1(m1)", ib_m1, 1, m1_1_bss, m1_1_azb, m1_1_wzb);
				break;
			case R.id.h5_ib_m2:
				setMx("设置玩家魔法区域2(m2)", ib_m2, 2, m1_2_bss, m1_2_azb, m1_2_wzb);
				break;
			case R.id.h5_ib_m7:
				setMx("设置AI魔法区域2(m2)", ib_m7, 3, m1_7_bss, m1_7_azb, m1_7_wzb);
				break;
			case R.id.h5_ib_m8:
				setMx("设置AI魔法区域1(m1)", ib_m8, 4, m1_8_bss, m1_8_azb, m1_8_wzb);
				break;
			case R.id.h5_ib_m9:
				setMx("设置玩家魔法区域0(m0)", ib_m9, 5, m1_9_bss, m1_9_azb, m1_9_wzb);
				break;
			case R.id.h5_ib_m10:
				setMx("设置玩家左刻度区域(l0)", ib_m10, 6, m1_10_bss, m1_10_azb, m1_10_wzb);
				break;		
			case R.id.h5_ib_m11:
				setMx("设置玩家右刻度区域(l1)", ib_m11, 7, m1_11_bss, m1_11_azb, m1_11_wzb);	
				break;
			case R.id.h5_ib_m12:
				setMx("设置AI右刻度区域(l1)", ib_m12, 8, m1_12_bss, m1_12_azb, m1_12_wzb);
				break;
			case R.id.h5_ib_m13:
				setMx("设置AI左刻度区域(l0)", ib_m13, 9, m1_13_bss, m1_13_azb, m1_13_wzb);		
				break;
			case R.id.h5_ib_m14:
				setMx("设置玩家场地区域(c0)", ib_m14, 10, m1_14_bss, m1_14_azb, m1_14_wzb);		
				break;		
			case R.id.h5_ib_m15:
				setMx("设置AI场地区域(c0)", ib_m15, 11, m1_15_bss, m1_15_azb, m1_15_wzb);
				break;
			case R.id.h5_ib_d0:			
				setList("设置玩家卡组", ib_d0, d1_0_kms);				
				break;
			case R.id.h5_ib_d1:
				setList("设置AI卡组", ib_d1, d1_1_kms);	
				break;	
			case R.id.h5_ib_d2:
				setList("设置玩家额外", ib_d2, d1_2_kms);	
				break;	
			case R.id.h5_ib_d3:
				setList("设置AI额外", ib_d3, d1_3_kms);	
				break;	
			case R.id.h5_ib_d4:
				setList("设置玩家墓地", ib_d4, d1_4_kms);	
				break;	
			case R.id.h5_ib_d5:
				setList("设置AI墓地", ib_d5, d1_5_kms);	
				break;	
			case R.id.h5_ib_d6:
				setList("设置玩家除外", ib_d6, d1_6_kms);	
				break;	
			case R.id.h5_ib_d7:
				setList("设置AI除外", ib_d7, d1_7_kms);	
				break;	
		}
	}
	
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		this.setContentView(R.layout.h5_layout);
		setkt(new SetKt());
		ed_cjm = (EditText)findViewById(R.id.h5_ed_cjm);
		ib_g0 = (ImageButton)findViewById(R.id.h5_ib_g0);
		ib_g1 = (ImageButton)findViewById(R.id.h5_ib_g1);
		ib_g2= (ImageButton)findViewById(R.id.h5_ib_g2);
		ib_g3= (ImageButton)findViewById(R.id.h5_ib_g3);
		ib_g4= (ImageButton)findViewById(R.id.h5_ib_g4);
		ib_g5= (ImageButton)findViewById(R.id.h5_ib_g5);
		ib_g6 = (ImageButton)findViewById(R.id.h5_ib_g6);
		ib_g7= (ImageButton)findViewById(R.id.h5_ib_g7);
		ib_g8= (ImageButton)findViewById(R.id.h5_ib_g8);
		ib_g9= (ImageButton)findViewById(R.id.h5_ib_g9);
		ib_m0 = (ImageButton)findViewById(R.id.h5_ib_m0);
		ib_m1 = (ImageButton)findViewById(R.id.h5_ib_m1);
		ib_m2= (ImageButton)findViewById(R.id.h5_ib_m2);
		ib_m7= (ImageButton)findViewById(R.id.h5_ib_m7);
		ib_m8= (ImageButton)findViewById(R.id.h5_ib_m8);
		ib_m9= (ImageButton)findViewById(R.id.h5_ib_m9);
		ib_m10 = (ImageButton)findViewById(R.id.h5_ib_m10);
		ib_m11 = (ImageButton)findViewById(R.id.h5_ib_m11);
		ib_m12= (ImageButton)findViewById(R.id.h5_ib_m12);
		ib_m13= (ImageButton)findViewById(R.id.h5_ib_m13);
		ib_m14= (ImageButton)findViewById(R.id.h5_ib_m14);
		ib_m15= (ImageButton)findViewById(R.id.h5_ib_m15);
		ib_d0=(ImageButton)findViewById(R.id.h5_ib_d0);
		ib_d1=(ImageButton)findViewById(R.id.h5_ib_d1);
		ib_d2=(ImageButton)findViewById(R.id.h5_ib_d2);
		ib_d3=(ImageButton)findViewById(R.id.h5_ib_d3);
		ib_d4=(ImageButton)findViewById(R.id.h5_ib_d4);
		ib_d5=(ImageButton)findViewById(R.id.h5_ib_d5);
		ib_d6=(ImageButton)findViewById(R.id.h5_ib_d6);
		ib_d7=(ImageButton)findViewById(R.id.h5_ib_d7);
		ib_link1=(ImageButton) findViewById(R.id.h5_ib_link1);
		ib_link2=(ImageButton) findViewById(R.id.h5_ib_link2);
		Toolbar tool=(Toolbar) findViewById(R.id.toolbar);
		
		
		gj=Gongju.getdx(this);
		du=DialogUtils.getdx(this);
		
		gj.cshToolbar(tool,"残局编辑");

		ib_g0.setOnClickListener(this);
		ib_g1.setOnClickListener(this);
		ib_g2.setOnClickListener(this);
		ib_g3.setOnClickListener(this);
		ib_g4.setOnClickListener(this);
		ib_g5.setOnClickListener(this);
		ib_g6.setOnClickListener(this);
		ib_g7.setOnClickListener(this);
		ib_g8.setOnClickListener(this);
		ib_g9.setOnClickListener(this);
		ib_m0.setOnClickListener(this);
		ib_m1.setOnClickListener(this);
		ib_m2.setOnClickListener(this);
		
		ib_m7.setOnClickListener(this);
		ib_m8.setOnClickListener(this);
		ib_m9.setOnClickListener(this);
		ib_m10.setOnClickListener(this);
		ib_m11.setOnClickListener(this);
		ib_m12.setOnClickListener(this);
		ib_m13.setOnClickListener(this);
		ib_m14.setOnClickListener(this);
		ib_m15.setOnClickListener(this);
		ib_d0.setOnClickListener(this);
		ib_d1.setOnClickListener(this);
		ib_d2.setOnClickListener(this);
		ib_d3.setOnClickListener(this);
		ib_d4.setOnClickListener(this);
		ib_d5.setOnClickListener(this);
		ib_d6.setOnClickListener(this);
		ib_d7.setOnClickListener(this);
		ib_link1.setOnClickListener(this);
		ib_link2.setOnClickListener(this);
		
		sjk_path=SharedPreferenceUtil.getYgopath();
	
	}
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		// TODO: Implement this method
		super.onActivityResult(requestCode, resultCode, data);
		//获取返回的值
		String result= data.getStringExtra("path");
		if (!result.equals(""))
		{
			
			sp_0.clear();
			sp_1.clear();
			try
			{
				File f=new File(result);
				FileInputStream fis=new FileInputStream(f);
				Properties p=new Properties();
				p.load(fis);
				if(p.getProperty("CJversion")==null||!p.getProperty("CJversion").equals(CJ_VERSION)){
					gj.show("该存档版本号与软件不匹配");
				}else{
					
					
					
				String temp;
				ed_cjm.setText(p.getProperty("cjm"));
				AIname=p.getProperty("AIname");
				kaiChangTiShi=p.getProperty("kaiChangTiShi");
				xue1=p.getProperty("xue1");
				xue2=p.getProperty("xue2");
				temp=p.getProperty("sp_0");
				zhuan(sp_0,temp);
				temp=p.getProperty("sp_1");
				zhuan(sp_1,temp);
				xp=Integer.parseInt(p.getProperty("xp"));
				temp=p.getProperty("g0_0_km");
				
				g0_0_km=temp;
				g0_0_bs=p.getProperty("g0_0_bs");
				g0_0_bss=Integer.parseInt(p.getProperty("g0_0_bss"));
				
					if (temp.equals(""))
						ib_g0.setImageBitmap(null);
					else
						oncard.onsetkt(ib_g0,temp,0,g0_0_bss);
				temp=p.getProperty("g0_0_sc");
				zhuan(g0_0_sc,temp);
				temp=p.getProperty("g0_1_km");
				
				g0_1_km=temp;
				g0_1_bs=p.getProperty("g0_1_bs");
				g0_1_bss=Integer.parseInt(p.getProperty("g0_1_bss"));
					if (temp.equals(""))
						ib_g1.setImageBitmap(null);
					else
						oncard.onsetkt(ib_g1,temp,0,g0_1_bss);
				
				temp=p.getProperty("g0_1_sc");
				zhuan(g0_1_sc,temp);
				temp=p.getProperty("g0_2_km");
				
				g0_2_km=temp;
				g0_2_bs=p.getProperty("g0_2_bs");
				g0_2_bss=Integer.parseInt(p.getProperty("g0_2_bss"));
					if (temp.equals(""))
						ib_g2.setImageBitmap(null);
					else
						oncard.onsetkt(ib_g2,temp,0,g0_2_bss);
				
				temp=p.getProperty("g0_2_sc");
				zhuan(g0_2_sc,temp);
				temp=p.getProperty("g0_3_km");
				
				g0_3_km=temp;
				g0_3_bs=p.getProperty("g0_3_bs");
				g0_3_bss=Integer.parseInt(p.getProperty("g0_3_bss"));
					if (temp.equals(""))
						ib_g3.setImageBitmap(null);
					else
						oncard.onsetkt(ib_g3,temp,0,g0_3_bss);
					
				
				temp=p.getProperty("g0_3_sc");
				zhuan(g0_3_sc,temp);
				temp=p.getProperty("g0_4_km");
			
				g0_4_km=temp;
				g0_4_bs=p.getProperty("g0_4_bs");
				g0_4_bss=Integer.parseInt(p.getProperty("g0_4_bss"));
				if (temp.equals(""))
					ib_g4.setImageBitmap(null);
				else
					oncard.onsetkt(ib_g4,temp,0,g0_4_bss);
					
				
				temp=p.getProperty("g0_4_sc");
				zhuan(g0_4_sc,temp);
				temp=p.getProperty("g1_4_km");
				
				g1_4_km=temp;
				g1_4_bs=p.getProperty("g1_4_bs");
				g1_4_bss=Integer.parseInt(p.getProperty("g1_4_bss"));
					if (temp.equals(""))
						ib_g5.setImageBitmap(null);
					else
						oncard.onsetkt(ib_g5,temp,0,g1_4_bss);
						
				temp=p.getProperty("g1_4_sc");
				zhuan(g1_4_sc,temp);
				temp=p.getProperty("g1_3_km");
				
				g1_3_km=temp;
				g1_3_bs=p.getProperty("g1_3_bs");
				g1_3_bss=Integer.parseInt(p.getProperty("g1_3_bss"));
				
					if (temp.equals(""))
						ib_g6.setImageBitmap(null);
					else
						oncard.onsetkt(ib_g6,temp,0,g1_3_bss);
					
				temp=p.getProperty("g1_3_sc");
				zhuan(g1_3_sc,temp);
				temp=p.getProperty("g1_2_km");
				
				g1_2_km=temp;
				g1_2_bs=p.getProperty("g1_2_bs");
				g1_2_bss=Integer.parseInt(p.getProperty("g1_2_bss"));
					if (temp.equals(""))
						ib_g7.setImageBitmap(null);
					else
						oncard.onsetkt(ib_g7,temp,0,g1_2_bss);
					
				
				temp=p.getProperty("g1_2_sc");
				zhuan(g1_2_sc,temp);
				temp=p.getProperty("g1_1_km");
				
				g1_1_km=temp;
				g1_1_bs=p.getProperty("g1_1_bs");
				g1_1_bss=Integer.parseInt(p.getProperty("g1_1_bss"));
					if (temp.equals(""))
						ib_g8.setImageBitmap(null);
					else
						oncard.onsetkt(ib_g8,temp,0,g1_1_bss);
					
				
				temp=p.getProperty("g1_1_sc");
				zhuan(g1_1_sc,temp);
				temp=p.getProperty("g1_0_km");
				
				g1_0_km=temp;
				g1_0_bs=p.getProperty("g1_0_bs");
				g1_0_bss=Integer.parseInt(p.getProperty("g1_0_bss"));
				
					if (temp.equals(""))
						ib_g9.setImageBitmap(null);
					else
						oncard.onsetkt(ib_g9,temp,0,g1_0_bss);
					
				temp=p.getProperty("g1_0_sc");
				zhuan(g1_0_sc,temp);
				
				temp=p.getProperty("g0_5_km");
					
					g0_5_km=temp;
					g0_5_bs=p.getProperty("g0_5_bs");
					g0_5_bss=Integer.parseInt(p.getProperty("g0_5_bss"));
					
				if (temp.equals("")){
					islink1=false;
					temp=p.getProperty("g1_6_km");
					
					g1_6_km=temp;
					g1_6_bs=p.getProperty("g1_6_bs");
					g1_6_bss=Integer.parseInt(p.getProperty("g1_6_bss"));
					
					if (temp.equals(""))
						ib_link1.setImageBitmap(null);
					else
						oncard.onsetkt(ib_link1,temp,0,g1_6_bss);
					
					temp=p.getProperty("g1_6_sc");
					zhuan(g1_6_sc,temp);
					
				}else{
					islink1=true;
					oncard.onsetkt(ib_link1,temp,0,g0_5_bss);
					
					}
				
					temp=p.getProperty("g0_5_sc");
					zhuan(g1_0_sc,temp);
					
				
				temp=p.getProperty("g0_6_km");
					g0_6_km=temp;
					g0_6_bs=p.getProperty("g0_6_bs");
					g0_6_bss=Integer.parseInt(p.getProperty("g0_6_bss"));
					
				if (temp.equals("")){
					islink2=false;
					temp=p.getProperty("g1_5_km");
				
						g1_5_km=temp;
						g1_5_bs=p.getProperty("g1_5_bs");
						g1_5_bss=Integer.parseInt(p.getProperty("g1_5_bss"));
					if (temp.equals(""))
						ib_link2.setImageBitmap(null);
					else
						oncard.onsetkt(ib_link2,temp,0,g1_5_bss);
					
						
						temp=p.getProperty("g1_5_sc");
						zhuan(g1_5_sc,temp);

						
					}else{
						islink2=true;
						oncard.onsetkt(ib_link2,temp,0,g0_6_bss);
						
					}
						temp=p.getProperty("g0_6_sc");
					zhuan(g0_6_sc,temp);
					
				temp=p.getProperty("m1_0_km");
				
				m1_0_km=temp;
				m1_0_bs=p.getProperty("m1_0_bs");
				m1_0_bss=Integer.parseInt(p.getProperty("m1_0_bss"));
					if (temp.equals(""))
					ib_m0.setImageBitmap(null);
					else
					oncard.onsetkt(ib_m0,temp,1,m1_0_bss);
				
				temp=p.getProperty("m1_0_azb");
				zhuan(m1_0_azb,temp);
				temp=p.getProperty("m1_0_wzb");
				zhuan(m1_0_wzb,temp);
				temp=p.getProperty("m1_1_km");
				
				m1_1_km=temp;
				m1_1_bs=p.getProperty("m1_1_bs");
				m1_1_bss=Integer.parseInt(p.getProperty("m1_1_bss"));
					if (temp.equals(""))
						ib_m1.setImageBitmap(null);
					else
						oncard.onsetkt(ib_m1,temp,1,m1_1_bss);
					
				
				
				temp=p.getProperty("m1_1_azb");
				zhuan(m1_1_azb,temp);
				temp=p.getProperty("m1_1_wzb");
				zhuan(m1_1_wzb,temp);
				temp=p.getProperty("m1_2_km");
					
				m1_2_km=temp;
				m1_2_bs=p.getProperty("m1_2_bs");
				m1_2_bss=Integer.parseInt(p.getProperty("m1_2_bss"));
					if (temp.equals(""))
						ib_m2.setImageBitmap(null);
					else
						oncard.onsetkt(ib_m2,temp,1,m1_2_bss);
					
				
				temp=p.getProperty("m1_2_azb");
				zhuan(m1_2_azb,temp);
				temp=p.getProperty("m1_2_wzb");
				zhuan(m1_2_wzb,temp);
			
				temp=p.getProperty("m1_7_km");
				
				m1_7_km=temp;
				m1_7_bs=p.getProperty("m1_7_bs");
				m1_7_bss=Integer.parseInt(p.getProperty("m1_7_bss"));
					if (temp.equals(""))
						ib_m7.setImageBitmap(null);
					else
						oncard.onsetkt(ib_m7,temp,1,m1_7_bss);
					
				
				temp=p.getProperty("m1_7_azb");
				zhuan(m1_7_azb,temp);
				temp=p.getProperty("m1_7_wzb");
				zhuan(m1_7_wzb,temp);
				temp=p.getProperty("m1_8_km");
				
				m1_8_km=temp;
				m1_8_bs=p.getProperty("m1_8_bs");
				m1_8_bss=Integer.parseInt(p.getProperty("m1_8_bss"));
					if (temp.equals(""))
						ib_m8.setImageBitmap(null);
					else
						oncard.onsetkt(ib_m8,temp,1,m1_8_bss);
					
				
				temp=p.getProperty("m1_8_azb");
				zhuan(m1_8_azb,temp);
				temp=p.getProperty("m1_8_wzb");
				zhuan(m1_8_wzb,temp);
				temp=p.getProperty("m1_9_km");
				
				m1_9_km=temp;
				m1_9_bs=p.getProperty("m1_9_bs");
				m1_9_bss=Integer.parseInt(p.getProperty("m1_9_bss"));
					if (temp.equals(""))
						ib_m9.setImageBitmap(null);
					else
						oncard.onsetkt(ib_m9,temp,1,m1_9_bss);
					
				
				temp=p.getProperty("m1_9_azb");
				zhuan(m1_9_azb,temp);
				temp=p.getProperty("m1_9_wzb");
				zhuan(m1_9_wzb,temp);
				temp=p.getProperty("m1_10_km");
				
				m1_10_km=temp;
				m1_10_bs=p.getProperty("m1_10_bs");
				m1_10_bss=Integer.parseInt(p.getProperty("m1_10_bss"));
					if (temp.equals(""))
						ib_m10.setImageBitmap(null);
					else
						oncard.onsetkt(ib_m10,temp,1,m1_10_bss);
					
				
				
				temp=p.getProperty("m1_10_azb");
				zhuan(m1_10_azb,temp);
				temp=p.getProperty("m1_10_wzb");
				zhuan(m1_10_wzb,temp);
				temp=p.getProperty("m1_11_km");
				
				m1_11_km=temp;
				m1_11_bs=p.getProperty("m1_11_bs");
				m1_11_bss=Integer.parseInt(p.getProperty("m1_11_bss"));
					if (temp.equals(""))
						ib_m11.setImageBitmap(null);
					else
						oncard.onsetkt(ib_m11,temp,1,m1_11_bss);
					
				
				temp=p.getProperty("m1_11_azb");
				zhuan(m1_11_azb,temp);
				temp=p.getProperty("m1_11_wzb");
				zhuan(m1_11_wzb,temp);
				temp=p.getProperty("m1_12_km");
				
				m1_12_km=temp;
				m1_12_bs=p.getProperty("m1_12_bs");
				m1_12_bss=Integer.parseInt(p.getProperty("m1_12_bss"));
					if (temp.equals(""))
						ib_m12.setImageBitmap(null);
					else
						oncard.onsetkt(ib_m12,temp,1,m1_12_bss);
					
				
				temp=p.getProperty("m1_12_azb");
				zhuan(m1_12_azb,temp);
				temp=p.getProperty("m1_12_wzb");
				zhuan(m1_12_wzb,temp);
				temp=p.getProperty("m1_13_km");
				
				m1_13_km=temp;
				m1_13_bs=p.getProperty("m1_13_bs");
				m1_13_bss=Integer.parseInt(p.getProperty("m1_13_bss"));
					if (temp.equals(""))
						ib_m13.setImageBitmap(null);
					else
						oncard.onsetkt(ib_m13,temp,1,m1_13_bss);
					
				
				temp=p.getProperty("m1_13_azb");
				zhuan(m1_13_azb,temp);
				temp=p.getProperty("m1_13_wzb");
				zhuan(m1_13_wzb,temp);
				temp=p.getProperty("m1_14_km");
				
					
				m1_14_km=temp;
				m1_14_bs=p.getProperty("m1_14_bs");
				m1_14_bss=Integer.parseInt(p.getProperty("m1_14_bss"));
					if (temp.equals(""))
						ib_m14.setImageBitmap(null);
					else
						oncard.onsetkt(ib_m14,temp,1,m1_14_bss);
				
				temp=p.getProperty("m1_14_azb");
				zhuan(m1_14_azb,temp);
				temp=p.getProperty("m1_14_wzb");
				zhuan(m1_14_wzb,temp);
				temp=p.getProperty("m1_15_km");
				
					
				m1_15_km=temp;
				m1_15_bs=p.getProperty("m1_15_bs");
				m1_15_bss=Integer.parseInt(p.getProperty("m1_15_bss"));
					if (temp.equals(""))
						ib_m15.setImageBitmap(null);
					else
						oncard.onsetkt(ib_m15,temp,1,m1_15_bss);
				
				temp=p.getProperty("m1_15_azb");
				zhuan(m1_15_azb,temp);
				temp=p.getProperty("m1_15_wzb");
				zhuan(m1_15_wzb,temp);
				
				temp=p.getProperty("d1_0_kms");
				if (temp.equals("[]"))
					ib_d0.setImageBitmap(null);
				else
					ib_d0.setImageResource(R.drawable.image_16);
				zhuan(d1_0_kms,temp);
				temp=p.getProperty("d1_1_kms");
				if (temp.equals("[]"))
					ib_d1.setImageBitmap(null);
				else
						ib_d1.setImageResource(R.drawable.image_16);
				zhuan(d1_1_kms,temp);
				temp=p.getProperty("d1_2_kms");
				if (temp.equals("[]"))
					ib_d2.setImageBitmap(null);
				else
						ib_d2.setImageResource(R.drawable.image_16);
				zhuan(d1_2_kms,temp);
				temp=p.getProperty("d1_3_kms");
				if (temp.equals("[]"))
					ib_d3.setImageBitmap(null);
				else
						ib_d3.setImageResource(R.drawable.image_16);
				zhuan(d1_3_kms,temp);
				temp=p.getProperty("d1_4_kms");
				if (temp.equals("[]"))
					ib_d4.setImageBitmap(null);
				else
						ib_d4.setImageResource(R.drawable.image_16);
				zhuan(d1_4_kms,temp);
				temp=p.getProperty("d1_5_kms");
				if (temp.equals("[]"))
					ib_d5.setImageBitmap(null);
				else
						ib_d5.setImageResource(R.drawable.image_16);
				zhuan(d1_5_kms,temp);
				temp=p.getProperty("d1_6_kms");
				if (temp.equals("[]"))
					ib_d6.setImageBitmap(null);
				else
						ib_d6.setImageResource(R.drawable.image_16);
				zhuan(d1_6_kms,temp);
				temp=p.getProperty("d1_7_kms");
				if (temp.equals("[]"))
					ib_d7.setImageBitmap(null);
				else
						ib_d7.setImageResource(R.drawable.image_16);
				zhuan(d1_7_kms,temp);
				fis.close();
				}
			}
			catch (IOException e)
			{
				gj.show("读取存档失败,原因为"+e);
			}
		}
	}

	private void zhuan(ArrayList al, String temp)
	{
		al.clear();
		if(temp.equals("[]"))
			return;
		String s=temp.substring(1,temp.length()-1);
		String[] ss=s.split(", ");
		for(int i=0;i<ss.length;i++)
		{
			al.add(ss[i]);
		}
	}


	public boolean onCreateOptionsMenu(Menu menu)
	{
		getMenuInflater().inflate(R.menu.h5, menu);
		return super.onCreateOptionsMenu(menu);
	}
	public boolean onOptionsItemSelected(MenuItem item)
	{
		switch (item.getItemId())
		{
			case R.id.h5_m_shezhishoupai:
				{
					builder = new Dialog(this);
					builder.setTitle("设置手牌");
					builder.show();

					LayoutInflater inflater = LayoutInflater.from(this);
					View viewDialog = inflater.inflate(R.layout.h5_dialog_6, null);
					Display display = this.getWindowManager().getDefaultDisplay();
					int width = display.getWidth();
					int hight=display.getHeight();
					//设置对话框的宽高
					LayoutParams layoutParams = new LayoutParams(width * 90 / 100, hight * 80 / 100);
					builder.setContentView(viewDialog, layoutParams);
					final EditText ed_sp0=(EditText)viewDialog.findViewById(R.id.h5d_6_sp0);
					final EditText ed_sp1=(EditText)viewDialog.findViewById(R.id.h5d_6_sp1);
					Button bu_qd=(Button)viewDialog.findViewById(R.id.h5d_6_qd);
					String sss="";
					for (int i=0;i < sp_0.size();i++)
					{
						sss = sss + sp_0.get(i) + "\n";
					}
					ed_sp0.setText(sss);
					sss="";
					for (int i=0;i < sp_1.size();i++)
					{
						sss = sss + sp_1.get(i) + "\n";
					}
					ed_sp1.setText(sss);
					bu_qd.setOnClickListener(new OnClickListener(){
							public void onClick(View p1)
							{
								sp_0.clear();
								String[] ss=ed_sp0.getText().toString().trim().split("\n");
								for (int i=0;i < ss.length;i++)
								{
									if (!ss[i].equals(""))
									{
										sp_0.add(ss[i]);
									}
								}				
								sp_1.clear();
								ss=ed_sp1.getText().toString().trim().split("\n");
								for (int i=0;i < ss.length;i++)
								{
									if (!ss[i].equals(""))
									{
										sp_1.add(ss[i]);
									}
								}				
								builder.dismiss();
							}		
						});
					break;
				}
				case R.id.h5_m_teshusheding:
				{
					builder = new Dialog(this);
					builder.setTitle("特殊设定");
					builder.show();

					LayoutInflater inflater = LayoutInflater.from(this);
					View viewDialog = inflater.inflate(R.layout.h5_dialog_8, null);
					Display display = this.getWindowManager().getDefaultDisplay();
					int width = display.getWidth();
					int hight=display.getHeight();
					//设置对话框的宽高
					LayoutParams layoutParams = new LayoutParams(width * 73 / 100, LayoutParams.WRAP_CONTENT);
					builder.setContentView(viewDialog, layoutParams);
					final CheckBox cb_xp=(CheckBox)viewDialog.findViewById(R.id.h5d_8_xp);
					Button bu_qd=(Button)viewDialog.findViewById(R.id.h5d_8_qd);
					if(xp==1)
						cb_xp.setChecked(true);
					bu_qd.setOnClickListener(new OnClickListener(){
							public void onClick(View p1)
							{
								if(cb_xp.isChecked())
									xp=1;
								else
									xp=0;
								builder.dismiss();
							}		
						});
					break;
				}
			case R.id.h5_m_shezhiaimingcheng:
				{
					View[] vv=du.dialoge(true,"设置AI名称","请输入AI名称");
					final EditText ed=(EditText) vv[0];
					Button b1=(Button) vv[1];
					b1.setOnClickListener(new OnClickListener(){

							@Override
							public void onClick(View p1)
							{
								String s=ed.getText().toString().trim();
								if (TextUtils.isEmpty(s))
								{
									gj.show( "名称不能为空");
									return; 
								}
								AIname = s;
								du.dis();
								// TODO: Implement this method
							}
						});
					break;
				}
			case R.id.h5_m_shezhixueliang:
				{
					builder = new Dialog(this);
					builder.setTitle("设置血量");
					builder.show();

					LayoutInflater inflater = LayoutInflater.from(this);
					View viewDialog = inflater.inflate(R.layout.h5_dialog_2, null);
					Display display = this.getWindowManager().getDefaultDisplay();
					int width = display.getWidth();
					int hight=display.getHeight();
					//设置对话框的宽高
					LayoutParams layoutParams = new LayoutParams(width * 90 / 100, hight * 40 / 100);
					builder.setContentView(viewDialog, layoutParams);
					final EditText ed_wjx=(EditText)viewDialog.findViewById(R.id.h5d_2_wjx);
					final EditText ed_aix=(EditText)viewDialog.findViewById(R.id.h5d_2_aix);
					ed_wjx.setText(xue1);
					ed_aix.setText(xue2);
					Button bu_qd=(Button)viewDialog.findViewById(R.id.h5d_2_qd);
					bu_qd.setOnClickListener(new OnClickListener(){
							public void onClick(View p1)
							{
								String s1=ed_wjx.getText().toString().trim();
								String s2=ed_aix.getText().toString().trim();
								if (TextUtils.isEmpty(s1) || TextUtils.isEmpty(s2))
								{
									gj.show( "不能为空");
									return; 
								}
								xue1 = s1;
								xue2 = s2;
								builder.dismiss();
							}		
						});
					break;
				}
			case R.id.h5_m_shezhikaichangtishi:
					View[] v=du.dialoge(true,"设置开场提示","");
					final EditText et;
					Button bt;
					et=(EditText) v[0];
					bt=(Button) v[1];
					bt.setOnClickListener(new OnClickListener(){

							@Override
							public void onClick(View p1)
							{
								
								String s1=et.getText().toString().trim();
								if (TextUtils.isEmpty(s1))
								{
									gj.show( "不能为空");
									
								}else{
								kaiChangTiShi = s1;
								du.dis();
								}
								// TODO: Implement this method
							}
						});
					break;
			case R.id.h5_m_cundang:
				{
					
					
					if (TextUtils.isEmpty(ed_cjm.getText().toString()))
					{
						gj.show( "残局名不能为空");
						break;
					}
					try{		
					
					final File f=new File(Gongju.PATH_EZ_MANAGEMENT+"archive/"+ed_cjm.getText().toString().trim()+".cjcd");
					final Properties p=new Properties();
					p.put("cjm",ed_cjm.getText().toString().trim());	
					p.put("CJversion",CJ_VERSION);
					p.put("AIname",AIname);
					p.put("kaiChangTiShi",kaiChangTiShi);
					p.put("xue1",xue1);
					p.put("xue2",xue2);
					p.put("sp_0",sp_0.toString());
					p.put("sp_1",sp_1.toString());
					p.put("xp",xp+"");
					p.put("g0_0_km",g0_0_km);
					p.put("g0_0_bs",g0_0_bs);
					p.put("g0_0_bss",g0_0_bss+"");
					p.put("g0_0_sc",g0_0_sc.toString());
					p.put("g0_1_km",g0_1_km);
					p.put("g0_1_bs",g0_1_bs);
					p.put("g0_1_bss",g0_1_bss+"");
					p.put("g0_1_sc",g0_1_sc.toString());
					p.put("g0_2_km",g0_2_km);
					p.put("g0_2_bs",g0_2_bs);
					p.put("g0_2_bss",g0_2_bss+"");
					p.put("g0_2_sc",g0_2_sc.toString());
					p.put("g0_3_km",g0_3_km);
					p.put("g0_3_bs",g0_3_bs);
					p.put("g0_3_bss",g0_3_bss+"");
					p.put("g0_3_sc",g0_3_sc.toString());
					p.put("g0_4_km",g0_4_km);
					p.put("g0_4_bs",g0_4_bs);
					p.put("g0_4_bss",g0_4_bss+"");
					p.put("g0_4_sc",g0_4_sc.toString());
					p.put("g1_4_km",g1_4_km);
					p.put("g1_4_bs",g1_4_bs);
					p.put("g1_4_bss",g1_4_bss+"");
					p.put("g1_4_sc",g1_4_sc.toString());
					p.put("g1_3_km",g1_3_km);
					p.put("g1_3_bs",g1_3_bs);
					p.put("g1_3_bss",g1_3_bss+"");
					p.put("g1_3_sc",g1_3_sc.toString());
					p.put("g1_2_km",g1_2_km);
					p.put("g1_2_bs",g1_2_bs);
					p.put("g1_2_bss",g1_2_bss+"");
					p.put("g1_2_sc",g1_2_sc.toString());
					p.put("g1_1_km",g1_1_km);
					p.put("g1_1_bs",g1_1_bs);
					p.put("g1_1_bss",g1_1_bss+"");
					p.put("g1_1_sc",g1_1_sc.toString());
					p.put("g1_0_km",g1_0_km);
					p.put("g1_0_bs",g1_0_bs);
					p.put("g1_0_bss",g1_0_bss+"");
					p.put("g1_0_sc",g1_0_sc.toString());

					p.put("g0_5_km",g0_5_km);
					p.put("g0_5_bs",g0_5_bs);
					p.put("g0_5_bss",g0_5_bss+"");
					p.put("g0_5_sc",g0_5_sc.toString());

					p.put("g1_6_km",g1_6_km);
					p.put("g1_6_bs",g1_6_bs);
					p.put("g1_6_bss",g1_6_bss+"");
					p.put("g1_6_sc",g1_6_sc.toString());

					p.put("g0_6_km",g0_6_km);
					p.put("g0_6_bs",g0_6_bs);
					p.put("g0_6_bss",g0_6_bss+"");
					p.put("g0_6_sc",g0_6_sc.toString());


					p.put("g1_5_km",g1_5_km);
					p.put("g1_5_bs",g1_5_bs);
					p.put("g1_5_bss",g1_5_bss+"");
					p.put("g1_5_sc",g1_5_sc.toString());


					p.put("m1_0_km",m1_0_km);
					p.put("m1_0_bs",m1_0_bs);
					p.put("m1_0_bss",m1_0_bss+"");
					p.put("m1_0_azb",m1_0_azb.toString());
					p.put("m1_0_wzb",m1_0_wzb.toString());
					p.put("m1_1_km",m1_1_km);
					p.put("m1_1_bs",m1_1_bs);
					p.put("m1_1_bss",m1_1_bss+"");
					p.put("m1_1_azb",m1_1_azb.toString());
					p.put("m1_1_wzb",m1_1_wzb.toString());
					p.put("m1_2_km",m1_2_km);
					p.put("m1_2_bs",m1_2_bs);
					p.put("m1_2_bss",m1_2_bss+"");
					p.put("m1_2_azb",m1_2_azb.toString());
					p.put("m1_2_wzb",m1_2_wzb.toString());

					p.put("m1_7_km",m1_7_km);
					p.put("m1_7_bs",m1_7_bs);
					p.put("m1_7_bss",m1_7_bss+"");
					p.put("m1_7_azb",m1_7_azb.toString());
					p.put("m1_7_wzb",m1_7_wzb.toString());
					p.put("m1_8_km",m1_8_km);
					p.put("m1_8_bs",m1_8_bs);
					p.put("m1_8_bss",m1_8_bss+"");
					p.put("m1_8_azb",m1_8_azb.toString());
					p.put("m1_8_wzb",m1_8_wzb.toString());
					p.put("m1_9_km",m1_9_km);
					p.put("m1_9_bs",m1_9_bs);
					p.put("m1_9_bss",m1_9_bss+"");
					p.put("m1_9_azb",m1_9_azb.toString());
					p.put("m1_9_wzb",m1_9_wzb.toString());
					p.put("m1_10_km",m1_10_km);
					p.put("m1_10_bs",m1_10_bs);
					p.put("m1_10_bss",m1_10_bss+"");
					p.put("m1_10_azb",m1_10_azb.toString());
					p.put("m1_10_wzb",m1_10_wzb.toString());
					p.put("m1_11_km",m1_11_km);
					p.put("m1_11_bs",m1_11_bs);
					p.put("m1_11_bss",m1_11_bss+"");
					p.put("m1_11_azb",m1_11_azb.toString());
					p.put("m1_11_wzb",m1_11_wzb.toString());
					p.put("m1_12_km",m1_12_km);
					p.put("m1_12_bs",m1_12_bs);
					p.put("m1_12_bss",m1_12_bss+"");
					p.put("m1_12_azb",m1_12_azb.toString());
					p.put("m1_12_wzb",m1_12_wzb.toString());
					p.put("m1_13_km",m1_13_km);
					p.put("m1_13_bs",m1_13_bs);
					p.put("m1_13_bss",m1_13_bss+"");
					p.put("m1_13_azb",m1_13_azb.toString());
					p.put("m1_13_wzb",m1_13_wzb.toString());
					p.put("m1_14_km",m1_14_km);
					p.put("m1_14_bs",m1_14_bs);
					p.put("m1_14_bss",m1_14_bss+"");
					p.put("m1_14_azb",m1_14_azb.toString());
					p.put("m1_14_wzb",m1_14_wzb.toString());
					p.put("m1_15_km",m1_15_km);
					p.put("m1_15_bs",m1_15_bs);
					p.put("m1_15_bss",m1_15_bss+"");
					p.put("m1_15_azb",m1_15_azb.toString());
					p.put("m1_15_wzb",m1_15_wzb.toString());
					p.put("d1_0_kms",d1_0_kms.toString());
					p.put("d1_1_kms",d1_1_kms.toString());
					p.put("d1_2_kms",d1_2_kms.toString());
					p.put("d1_3_kms",d1_3_kms.toString());
					p.put("d1_4_kms",d1_4_kms.toString());
					p.put("d1_5_kms",d1_5_kms.toString());
					p.put("d1_6_kms",d1_6_kms.toString());
					p.put("d1_7_kms",d1_7_kms.toString());
					
					if(f.exists())
					{
						
						View[] v1=du.dialogt(false,"","存档已存在,是否覆盖？");
						Button b1,b2;
						b1=(Button) v1[0];
						b2=(Button) v1[1];
						b1.setText("取消");
						b2.setText("覆盖");
						b1.setOnClickListener(new OnClickListener(){

								@Override
								public void onClick(View p1)
								{
									du.dis();
									// TODO: Implement this method
								}
							});
						b2.setOnClickListener(new OnClickListener(){

								@Override
								public void onClick(View p1)
								{
															
									try
									{
									FileOutputStream fos=new FileOutputStream(f);
									p.store(fos, "");
									fos.close();			
									}
									catch (IOException e)
									{
										gj.show("残局覆盖失败,原因为"+e);
									}
									
										gj.show("已覆盖");
								
									du.dis();

									// TODO: Implement this method
								}
							});
					}else{
						try{
							FileOutputStream fos=new FileOutputStream(f);
										
							p.store(fos,"");
							fos.close();
							gj.show("已保存到"+Gongju.PATH_EZ_MANAGEMENT+"archive/"+ed_cjm.getText().toString().trim()+".cjcd");
							
						}catch (Exception e){
							gj.show("残局保存失败,原因为"+e);
						}
						
						
					}
					
					}catch (Exception e){
						gj.show("保存失败,原因为"+e);
						break;
					}
					break;
				}
			case R.id.h5_m_dudang:
			{
				Intent intent=new Intent();
				intent.putExtra("lx",NewWjxz.TYPE_SINGLE_CUBDANG);
				intent.putExtra("path",Gongju.PATH_EZ_MANAGEMENT);
				intent.setClass(H5.this, NewWjxz.class);
				startActivityForResult(intent, 0);
				
				break;
			}
			case R.id.h5_m_baocun:
				{
					if (TextUtils.isEmpty(ed_cjm.getText().toString()))
					{
						gj.show( "残局名不能为空");
						break;
					}
					try
					{
						BufferedWriter br=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(sjk_path + "single/" + ed_cjm.getText().toString().trim() + ".lua"), "utf-8"));
						//标签
						br.write("--By OURYGO-YGO EZ manager\n");
						//设置AI名称
						br.write("Debug.SetAIName(\"" + AIname + "\")\n");
						//
						if(xp==1)
							br.write("Debug.ReloadFieldBegin(DUEL_ATTACK_FIRST_TURN+DUEL_SIMPLE_AI+DUEL_PSEUDO_SHUFFLE,4)" + "\n");
						else
							br.write("Debug.ReloadFieldBegin(DUEL_ATTACK_FIRST_TURN+DUEL_SIMPLE_AI,4)" + "\n");
						//设置玩家血量
						br.write("Debug.SetPlayerInfo(0," + xue1 + ",0,0)\n");
						//设置AI血量
						br.write("Debug.SetPlayerInfo(1," + xue2 + ",0,0)\n");
						//设置手牌
						if(sp_0.size()!=0)
						{
							for (int i=0;i < sp_0.size();i++)
							{
								br.write("Debug.AddCard("+sp_0.get(i)+",0,0,LOCATION_HAND,0,POS_FACEDOWN)\n");
							}
						}
						if(sp_1.size()!=0)
						{
							for (int i=0;i < sp_1.size();i++)
							{
								br.write("Debug.AddCard("+sp_1.get(i)+",1,1,LOCATION_HAND,0,POS_FACEDOWN)\n");
							}
						}
						
						
						
						//设置怪兽区域
						if (!g0_0_km.equals(""))
						{
							br.write("local g00=Debug.AddCard(" + g0_0_km + ",0,0,LOCATION_MZONE,0," + g0_0_bs + ")\n");
							for (int i=0;i < g0_0_sc.size();i++)
							{
								br.write("Debug.AddCard(" + g0_0_sc.get(i) + ",0,0,LOCATION_MZONE,0,POS_FACEUP_ATTACK)\n");
							}
						}
						if (!g0_1_km.equals(""))
						{
							br.write("local g01=Debug.AddCard(" + g0_1_km + ",0,0,LOCATION_MZONE,1," + g0_1_bs + ")\n");
							for (int i=0;i < g0_1_sc.size();i++)
							{
								br.write("Debug.AddCard(" + g0_1_sc.get(i) + ",0,0,LOCATION_MZONE,1,POS_FACEUP_ATTACK)\n");
							}
						}
						if (!g0_2_km.equals(""))
						{
							br.write("local g02=Debug.AddCard(" + g0_2_km + ",0,0,LOCATION_MZONE,2," + g0_2_bs + ")\n");
							for (int i=0;i < g0_2_sc.size();i++)
							{
								br.write("Debug.AddCard(" + g0_2_sc.get(i) + ",0,0,LOCATION_MZONE,2,POS_FACEUP_ATTACK)\n");
							}
						}
						if (!g0_3_km.equals(""))
						{
							br.write("local g03=Debug.AddCard(" + g0_3_km + ",0,0,LOCATION_MZONE,3," + g0_3_bs + ")\n");
							for (int i=0;i < g0_3_sc.size();i++)
							{
								br.write("Debug.AddCard(" + g0_3_sc.get(i) + ",0,0,LOCATION_MZONE,3,POS_FACEUP_ATTACK)\n");
							}
						}
						if (!g0_4_km.equals(""))
						{
							br.write("local g04=Debug.AddCard(" + g0_4_km + ",0,0,LOCATION_MZONE,4," + g0_4_bs + ")\n");
							for (int i=0;i < g0_4_sc.size();i++)
							{
								br.write("Debug.AddCard(" + g0_4_sc.get(i) + ",0,0,LOCATION_MZONE,4,POS_FACEUP_ATTACK)\n");
							}
						}
						if (!g1_4_km.equals(""))
						{
							br.write("local g14=Debug.AddCard(" + g1_4_km + ",1,1,LOCATION_MZONE,4," + g1_4_bs + ")\n");
							for (int i=0;i < g1_4_sc.size();i++)
							{
								br.write("Debug.AddCard(" + g1_4_sc.get(i) + ",1,1,LOCATION_MZONE,4,POS_FACEUP_ATTACK)\n");
							}
						}
						if (!g1_3_km.equals(""))
						{
							br.write("local g13=Debug.AddCard(" + g1_3_km + ",1,1,LOCATION_MZONE,3," + g1_3_bs + ")\n");
							for (int i=0;i < g1_3_sc.size();i++)
							{
								br.write("Debug.AddCard(" + g1_3_sc.get(i) + ",1,1,LOCATION_MZONE,3,POS_FACEUP_ATTACK)\n");
							}
						}
						if (!g1_2_km.equals(""))
						{
							br.write("local g12=Debug.AddCard(" + g1_2_km + ",1,1,LOCATION_MZONE,2," + g1_2_bs + ")\n");
							for (int i=0;i < g1_2_sc.size();i++)
							{
								br.write("Debug.AddCard(" + g1_2_sc.get(i) + ",1,1,LOCATION_MZONE,2,POS_FACEUP_ATTACK)\n");
							}
						}
						if (!g1_1_km.equals(""))
						{
							br.write("local g11=Debug.AddCard(" + g1_1_km + ",1,1,LOCATION_MZONE,1," + g1_1_bs + ")\n");
							for (int i=0;i < g1_1_sc.size();i++)
							{
								br.write("Debug.AddCard(" + g1_1_sc.get(i) + ",1,1,LOCATION_MZONE,1,POS_FACEUP_ATTACK)\n");
							}
						}
						if (!g1_0_km.equals(""))
						{
							br.write("local g10=Debug.AddCard(" + g1_0_km + ",1,1,LOCATION_MZONE,0," + g1_0_bs + ")\n");
							for (int i=0;i < g1_0_sc.size();i++)
							{
								br.write("Debug.AddCard(" + g1_0_sc.get(i) + ",1,1,LOCATION_MZONE,0,POS_FACEUP_ATTACK)\n");
							}
						}
						
						//设置link0
						if (islink1)
						{
							br.write("local link0=Debug.AddCard(" + g0_5_km + ",0,0,LOCATION_MZONE,5," + g0_5_bs + ")\n");
							for (int i=0;i < g0_5_sc.size();i++)
							{
								br.write("Debug.AddCard(" + g0_5_sc.get(i) + ",0,0,LOCATION_MZONE,5,POS_FACEUP_ATTACK)\n");
							}
						}else if (!g1_6_km.equals("")){
							br.write("local link0=Debug.AddCard(" + g1_6_km + ",1,1,LOCATION_MZONE,6," + g1_6_bs + ")\n");
							for (int i=0;i < g1_6_sc.size();i++)
							{
								br.write("Debug.AddCard(" + g1_6_sc.get(i) + ",1,1,LOCATION_MZONE,6,POS_FACEUP_ATTACK)\n");
							}
						}
						
						//设置link1
						if (islink2)
						{
							br.write("local link1=Debug.AddCard(" + g0_6_km + ",0,0,LOCATION_MZONE,6," + g0_6_bs + ")\n");
							for (int i=0;i < g1_0_sc.size();i++)
							{
								br.write("Debug.AddCard(" + g0_6_sc.get(i) + ",0,0,LOCATION_MZONE,6,POS_FACEUP_ATTACK)\n");
							}
						}else if (!g1_5_km.equals(""))
						{
							br.write("local link1=Debug.AddCard(" + g1_5_km + ",1,1,LOCATION_MZONE,5," + g1_5_bs + ")\n");
							for (int i=0;i < g1_5_sc.size();i++)
							{
								br.write("Debug.AddCard(" + g1_5_sc.get(i) + ",1,1,LOCATION_MZONE,5,POS_FACEUP_ATTACK)\n");
							}
						}
						
						
						//设置魔法区域
						if (!m1_0_km.equals(""))
						{
							br.write("local m01=Debug.AddCard(" + m1_0_km + ",0,0,LOCATION_SZONE,1," + m1_0_bs + ")\n");
						}
						if (!m1_1_km.equals(""))
						{
							br.write("local m02=Debug.AddCard(" + m1_1_km + ",0,0,LOCATION_SZONE,2," + m1_1_bs + ")\n");
						}
						if (!m1_2_km.equals(""))
						{
							br.write("local m03=Debug.AddCard(" + m1_2_km + ",0,0,LOCATION_SZONE,3," + m1_2_bs + ")\n");
						}
						
						if (!m1_7_km.equals(""))
						{
							br.write("local m11=Debug.AddCard(" + m1_7_km + ",1,1,LOCATION_SZONE,3," + m1_7_bs + ")\n");
						}
						if (!m1_8_km.equals(""))
						{
							br.write("local m12=Debug.AddCard(" + m1_8_km + ",1,1,LOCATION_SZONE,2," + m1_8_bs + ")\n");
						}
						if (!m1_9_km.equals(""))
						{
							br.write("local m13=Debug.AddCard(" + m1_9_km + ",1,1,LOCATION_SZONE,1," + m1_9_bs + ")\n");
						}
						//设置灵摆区域
						if (!m1_10_km.equals(""))
						{
							br.write("local m00=Debug.AddCard(" + m1_10_km + ",0,0,LOCATION_SZONE,0," + m1_10_bs + ")\n");
						}
						if (!m1_11_km.equals(""))
						{
							br.write("local m04=Debug.AddCard(" + m1_11_km + ",0,0,LOCATION_SZONE,4," + m1_11_bs + ")\n");
						}
						if (!m1_12_km.equals(""))
						{
							br.write("local m10=Debug.AddCard(" + m1_12_km + ",1,1,LOCATION_SZONE,0," + m1_12_bs + ")\n");
						}
						if (!m1_13_km.equals(""))
						{
							br.write("local m14=Debug.AddCard(" + m1_13_km + ",1,1,LOCATION_SZONE,4," + m1_13_bs + ")\n");
						}
						//设置场地
						if (!m1_14_km.equals(""))
						{
							br.write("local c0=Debug.AddCard(" + m1_14_km + ",0,0,LOCATION_SZONE,5," + m1_14_bs + ")\n");
						}
						if (!m1_15_km.equals(""))
						{
							br.write("local c1=Debug.AddCard(" + m1_15_km + ",1,1,LOCATION_SZONE,5," + m1_15_bs + ")\n");
						}
						//设置卡组
						for(int i=d1_0_kms.size()-1;i>=0;i--)
						{
							if(!d1_0_kms.get(i).equals(""))
								br.write("Debug.AddCard("+d1_0_kms.get(i)+",0,0,LOCATION_DECK,0,POS_FACEUP_ATTACK)\n");
						}
						for(int i=d1_1_kms.size()-1;i>=0;i--)
						{
							if(!d1_1_kms.get(i).equals(""))
								br.write("Debug.AddCard("+d1_1_kms.get(i)+",1,1,LOCATION_DECK,0,POS_FACEUP_ATTACK)\n");
						}
						//设置额外
						for(int i=d1_2_kms.size()-1;i>=0;i--)
						{
							if(!d1_2_kms.get(i).equals(""))
								br.write("Debug.AddCard("+d1_2_kms.get(i)+",0,0,LOCATION_EXTRA,0,POS_FACEDOWN)");
						}
						for(int i=d1_3_kms.size()-1;i>=0;i--)
						{
							if(!d1_3_kms.get(i).equals(""))
								br.write("Debug.AddCard("+d1_3_kms.get(i)+",1,1,LOCATION_EXTRA,0,POS_FACEDOWN)");
						}
						//设置墓地
						for(int i=d1_4_kms.size()-1;i>=0;i--)
						{
							if(!d1_4_kms.get(i).equals(""))
								br.write("Debug.AddCard("+d1_4_kms.get(i)+",0,0,LOCATION_GRAVE,0,POS_FACEUP)");
						}
						for(int i=d1_5_kms.size()-1;i>=0;i--)
						{
							if(!d1_5_kms.get(i).equals(""))
								br.write("Debug.AddCard("+d1_5_kms.get(i)+",1,1,LOCATION_GRAVE,0,POS_FACEUP)");
						}
						//设置除外
						for(int i=d1_6_kms.size()-1;i>=0;i--)
						{
							if(!d1_6_kms.get(i).equals(""))
								br.write("Debug.AddCard("+d1_6_kms.get(i)+",0,0,LOCATION_REMOVED,0,POS_FACEUP)");
						}
						for(int i=d1_7_kms.size()-1;i>=0;i--)
						{
							if(!d1_7_kms.get(i).equals(""))
								br.write("Debug.AddCard("+d1_7_kms.get(i)+",1,1,LOCATION_REMOVED,0,POS_FACEUP)");
						}
						//设置装备效果
						if (!m1_0_km.equals(""))
						{
							for (int i=0;i < m1_0_azb.size();i++)
							{
								br.write("Debug.PreEquip(m01,"+m1_0_azb.get(i)+")\n");
							}
							for (int i=0;i < m1_0_wzb.size();i++)
							{
								br.write("Debug.PreEquip(m01,"+m1_0_wzb.get(i)+")\n");
							}
						}
						if (!m1_1_km.equals(""))
						{
							for (int i=0;i < m1_1_azb.size();i++)
							{
								br.write("Debug.PreEquip(m02,"+m1_1_azb.get(i)+")\n");
							}
							for (int i=0;i < m1_1_wzb.size();i++)
							{
								br.write("Debug.PreEquip(m02,"+m1_1_wzb.get(i)+")\n");
							}
						}
						if (!m1_2_km.equals(""))
						{
							for (int i=0;i < m1_2_azb.size();i++)
							{
								br.write("Debug.PreEquip(m03,"+m1_2_azb.get(i)+")\n");
							}
							for (int i=0;i < m1_2_wzb.size();i++)
							{
								br.write("Debug.PreEquip(m03,"+m1_2_wzb.get(i)+")\n");
							}
						}
						
						
						if (!m1_7_km.equals(""))
						{
							for (int i=0;i < m1_7_azb.size();i++)
							{
								br.write("Debug.PreEquip(m11,"+m1_7_azb.get(i)+")\n");
							}
							for (int i=0;i < m1_7_wzb.size();i++)
							{
								br.write("Debug.PreEquip(m11,"+m1_7_wzb.get(i)+")\n");
							}
						}
						if (!m1_8_km.equals(""))
						{
							for (int i=0;i < m1_8_azb.size();i++)
							{
								br.write("Debug.PreEquip(m12,"+m1_8_azb.get(i)+")\n");
							}
							for (int i=0;i < m1_8_wzb.size();i++)
							{
								br.write("Debug.PreEquip(m12,"+m1_8_wzb.get(i)+")\n");
							}
						}
						if (!m1_9_km.equals(""))
						{
							for (int i=0;i < m1_9_azb.size();i++)
							{
								br.write("Debug.PreEquip(m13,"+m1_9_azb.get(i)+")\n");
							}
							for (int i=0;i < m1_9_wzb.size();i++)
							{
								br.write("Debug.PreEquip(m13,"+m1_9_wzb.get(i)+")\n");
							}
						}
						if (!m1_10_km.equals(""))
						{
							for (int i=0;i < m1_10_azb.size();i++)
							{
								br.write("Debug.PreEquip(m00,"+m1_10_azb.get(i)+")\n");
							}
							for (int i=0;i < m1_10_wzb.size();i++)
							{
								br.write("Debug.PreEquip(m00,"+m1_10_wzb.get(i)+")\n");
							}
						}
						if (!m1_11_km.equals(""))
						{
							for (int i=0;i < m1_11_azb.size();i++)
							{
								br.write("Debug.PreEquip(m04,"+m1_11_azb.get(i)+")\n");
							}
							for (int i=0;i < m1_11_wzb.size();i++)
							{
								br.write("Debug.PreEquip(m04,"+m1_11_wzb.get(i)+")\n");
							}
						}
						if (!m1_12_km.equals(""))
						{
							for (int i=0;i < m1_12_azb.size();i++)
							{
								br.write("Debug.PreEquip(m10,"+m1_12_azb.get(i)+")\n");
							}
							for (int i=0;i < m1_12_wzb.size();i++)
							{
								br.write("Debug.PreEquip(m10,"+m1_12_wzb.get(i)+")\n");
							}
						}
						if (!m1_13_km.equals(""))
						{
							for (int i=0;i < m1_13_azb.size();i++)
							{
								br.write("Debug.PreEquip(m14,"+m1_13_azb.get(i)+")\n");
							}
							for (int i=0;i < m1_13_wzb.size();i++)
							{
								br.write("Debug.PreEquip(m14,"+m1_13_wzb.get(i)+")\n");
							}
						}
						if (!m1_14_km.equals(""))
						{
							for (int i=0;i < m1_14_azb.size();i++)
							{
								br.write("Debug.PreEquip(c0,"+m1_14_azb.get(i)+")\n");
							}
							for (int i=0;i < m1_14_wzb.size();i++)
							{
								br.write("Debug.PreEquip(c0,"+m1_14_wzb.get(i)+")\n");
							}
						}
						if (!m1_15_km.equals(""))
						{
							for (int i=0;i < m1_15_azb.size();i++)
							{
								br.write("Debug.PreEquip(c1,"+m1_15_azb.get(i)+")\n");
							}
							for (int i=0;i < m1_15_wzb.size();i++)
							{
								br.write("Debug.PreEquip(c1,"+m1_15_wzb.get(i)+")\n");
							}
						}
						//
						br.write("Debug.ReloadFieldEnd()\n");
						//开场提示
						br.write("Debug.ShowHint(\"" + kaiChangTiShi + "\")\n");
						//
						br.write("aux.BeginPuzzle()\n");
						br.close();
					}
					catch (IOException e)
					{}
					gj.show( "已保存到" + sjk_path + "single/" + ed_cjm.getText().toString().trim() + ".lua");
					break;
				}
		}
		return true;
	}
	String AIname="高性能电子头脑";
	String kaiChangTiShi="在这个回合取得胜利！";
	String xue1="8000",xue2="8000";
	ArrayList sp_0=new ArrayList();
	ArrayList sp_1=new ArrayList();
	int xp=0;

	String g0_0_km="";
	String g0_0_bs="POS_FACEUP_ATTACK";
	int g0_0_bss=0;
	ArrayList g0_0_sc=new ArrayList();
	String g0_1_km="";
	String g0_1_bs="POS_FACEUP_ATTACK";
	int g0_1_bss=0;
	ArrayList g0_1_sc=new ArrayList();
	String g0_2_km="";
	String g0_2_bs="POS_FACEUP_ATTACK";
	int g0_2_bss=0;
	ArrayList g0_2_sc=new ArrayList();
	String g0_3_km="";
	String g0_3_bs="POS_FACEUP_ATTACK";
	int g0_3_bss=0;
	ArrayList g0_3_sc=new ArrayList();
	String g0_4_km="";
	String g0_4_bs="POS_FACEUP_ATTACK";
	int g0_4_bss=0;
	ArrayList g0_4_sc=new ArrayList();
	String g1_4_km="";
	String g1_4_bs="POS_FACEUP_ATTACK";
	int g1_4_bss=0;
	ArrayList g1_4_sc=new ArrayList();
	String g1_3_km="";
	String g1_3_bs="POS_FACEUP_ATTACK";
	int g1_3_bss=0;
	ArrayList g1_3_sc=new ArrayList();
	String g1_2_km="";
	String g1_2_bs="POS_FACEUP_ATTACK";
	int g1_2_bss=0;
	ArrayList g1_2_sc=new ArrayList();
	String g1_1_km="";
	String g1_1_bs="POS_FACEUP_ATTACK";
	int g1_1_bss=0;
	ArrayList g1_1_sc=new ArrayList();
	//该区域卡片卡密
	String g1_0_km="";
	String g1_0_bs="POS_FACEUP_ATTACK";
	//表示形式
	int g1_0_bss=0;
	//超量素材
	ArrayList g1_0_sc=new ArrayList();
	
	String g0_5_km="";
	String g0_5_bs="POS_FACEUP_ATTACK";
	int g0_5_bss=0;
	ArrayList g0_5_sc=new ArrayList();
	
	String g0_6_km="";
	String g0_6_bs="POS_FACEUP_ATTACK";
	int g0_6_bss=0;
	ArrayList g0_6_sc=new ArrayList();
	
	String g1_5_km="";
	String g1_5_bs="POS_FACEUP_ATTACK";
	int g1_5_bss=0;
	ArrayList g1_5_sc=new ArrayList();

	String g1_6_km="";
	String g1_6_bs="POS_FACEUP_ATTACK";
	int g1_6_bss=0;
	ArrayList g1_6_sc=new ArrayList();

	boolean islink1,islink2;
	

	String m1_0_km="";
	String m1_0_bs="POS_FACEDOW";
	int m1_0_bss=0;
	ArrayList m1_0_azb=new ArrayList();
	ArrayList m1_0_wzb=new ArrayList();
	String m1_1_km="";
	String m1_1_bs="POS_FACEDOW";
	int m1_1_bss=0;
	ArrayList m1_1_azb=new ArrayList();
	ArrayList m1_1_wzb=new ArrayList();
	String m1_2_km="";
	String m1_2_bs="POS_FACEDOW";
	int m1_2_bss=0;
	ArrayList m1_2_azb=new ArrayList();
	ArrayList m1_2_wzb=new ArrayList();
	/*String m1_3_km="";
	String m1_3_bs="POS_FACEDOW";
	int m1_3_bss=0;
	ArrayList m1_3_azb=new ArrayList();
	ArrayList m1_3_wzb=new ArrayList();
	String m1_4_km="";
	String m1_4_bs="POS_FACEDOW";
	int m1_4_bss=0;
	ArrayList m1_4_azb=new ArrayList();
	ArrayList m1_4_wzb=new ArrayList();*/
	/*String m1_5_km="";
	String m1_5_bs="POS_FACEDOW";
	int m1_5_bss=0;
	ArrayList m1_5_azb=new ArrayList();
	ArrayList m1_5_wzb=new ArrayList();
	String m1_6_km="";
	String m1_6_bs="POS_FACEDOW";
	int m1_6_bss=0;
	ArrayList m1_6_azb=new ArrayList();
	ArrayList m1_6_wzb=new ArrayList();*/
	String m1_7_km="";
	String m1_7_bs="POS_FACEDOW";
	int m1_7_bss=0;
	ArrayList m1_7_azb=new ArrayList();
	ArrayList m1_7_wzb=new ArrayList();
	String m1_8_km="";
	String m1_8_bs="POS_FACEDOW";
	int m1_8_bss=0;
	ArrayList m1_8_azb=new ArrayList();
	ArrayList m1_8_wzb=new ArrayList();
	String m1_9_km="";
	String m1_9_bs="POS_FACEDOW";
	int m1_9_bss=0;
	ArrayList m1_9_azb=new ArrayList();
	ArrayList m1_9_wzb=new ArrayList();
	String m1_10_km="";
	String m1_10_bs="POS_FACEDOW";
	int m1_10_bss=0;
	ArrayList m1_10_azb=new ArrayList();
	ArrayList m1_10_wzb=new ArrayList();
	String m1_11_km="";
	String m1_11_bs="POS_FACEDOW";
	int m1_11_bss=0;
	ArrayList m1_11_azb=new ArrayList();
	ArrayList m1_11_wzb=new ArrayList();
	String m1_12_km="";
	String m1_12_bs="POS_FACEDOW";
	int m1_12_bss=0;
	ArrayList m1_12_azb=new ArrayList();
	ArrayList m1_12_wzb=new ArrayList();
	String m1_13_km="";
	String m1_13_bs="POS_FACEDOW";
	int m1_13_bss=0;
	ArrayList m1_13_azb=new ArrayList();
	ArrayList m1_13_wzb=new ArrayList();
	String m1_14_km="";
	String m1_14_bs="POS_FACEDOW";
	int m1_14_bss=0;
	ArrayList m1_14_azb=new ArrayList();
	ArrayList m1_14_wzb=new ArrayList();
	String m1_15_km="";
	String m1_15_bs="POS_FACEDOW";
	int m1_15_bss=0;
	ArrayList m1_15_azb=new ArrayList();
	ArrayList m1_15_wzb=new ArrayList();
	
	ArrayList d1_0_kms=new ArrayList();
	ArrayList d1_1_kms=new ArrayList();
	ArrayList d1_2_kms=new ArrayList();
	ArrayList d1_3_kms=new ArrayList();
	ArrayList d1_4_kms=new ArrayList();
	ArrayList d1_5_kms=new ArrayList();
	ArrayList d1_6_kms=new ArrayList();
	ArrayList d1_7_kms=new ArrayList();
}
